package com.cmc.cloud.cmclink.doc.controller.admin.special;

import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.convert.SpecialCargoFlexiConvert;
import com.cmc.cloud.cmclink.doc.entity.SpecialCargoFlexiDO;
import com.cmc.cloud.cmclink.doc.service.SpecialCargoFlexiService;
import com.cmc.cloud.cmclink.doc.vo.specialcargoflexivo.SpecialCargoFlexiCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.specialcargoflexivo.SpecialCargoFlexiPageReqVO;
import com.cmc.cloud.cmclink.doc.vo.specialcargoflexivo.SpecialCargoFlexiRespVO;
import com.cmc.cloud.cmclink.doc.vo.specialcargoflexivo.SpecialCargoFlexiUpdateReqVO;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;


/**
 * 特种货审批flexi前端接口Controller
 *
 * @author codegen
 */
@Tag(name = "管理后台 - 特种货审批flexi")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "/specialCargoFlexi")
public class SpecialCargoFlexiController {

    @Resource
    private SpecialCargoFlexiService specialCargoFlexiService;

    @Operation(summary = "创建特种货审批flexi")
    @PostMapping("/create")
    public CommonResult<Void> createSpecialCargoFlexi(@Valid @RequestBody SpecialCargoFlexiCreateReqVO createReqVO) {
        specialCargoFlexiService.createSpecialCargoFlexi(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新特种货审批flexi")
    @PostMapping("/update")
    public CommonResult<Void> updateSpecialCargoFlexi(@Valid @RequestBody SpecialCargoFlexiUpdateReqVO updateReqVO) {
        specialCargoFlexiService.updateSpecialCargoFlexi(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除特种货审批flexi")
    @PostMapping("/delete/{id}")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Void> deleteSpecialCargoFlexi(@PathVariable("id") Long id) {
        specialCargoFlexiService.deleteSpecialCargoFlexi(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得特种货审批flexi")
    @GetMapping("/get/{cntrId}")
    @Parameter(name = "cntrId", description = "箱型ID", required = true, example = "1024")
    public CommonResult<SpecialCargoFlexiRespVO> getSpecialCargoFlexi(@PathVariable("cntrId") Long cntrId) {
        SpecialCargoFlexiDO specialCargoFlexi = specialCargoFlexiService.getSpecialCargoFlexi(cntrId);
        return CommonResult.success(SpecialCargoFlexiConvert.INSTANCE.convert(specialCargoFlexi));
    }

    @Operation(summary = "获得特种货审批flexi列表")
    @GetMapping("/list")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    public CommonResult<List<SpecialCargoFlexiRespVO>> getSpecialCargoFlexiList(@RequestParam("ids") Collection<Long> ids) {
        List<SpecialCargoFlexiDO> list = specialCargoFlexiService.getSpecialCargoFlexiList(ids);
        return CommonResult.success(SpecialCargoFlexiConvert.INSTANCE.convertList(list));
    }

    @Operation(summary = "获得特种货审批flexi分页")
    @PostMapping("/page")
    public CommonResult<PageResult<SpecialCargoFlexiRespVO>> getSpecialCargoFlexiPage(@RequestBody @Valid SpecialCargoFlexiPageReqVO pageVO) {
        PageResult<SpecialCargoFlexiDO> pageResult = specialCargoFlexiService.getSpecialCargoFlexiPage(pageVO);
        List<SpecialCargoFlexiRespVO> results = SpecialCargoFlexiConvert.INSTANCE.convertList(pageResult.getList());
        return CommonResult.success(new PageResult<>(results, pageResult.getTotal()));
    }
}
